/**
 * Created by as on 2018/1/3.
 */
/**
 * 判断ie版本
 * @returns {*}
 * @constructor
 */
function IEVersion() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if(fIEVersion == 7) {
            return 7;
        } else if(fIEVersion == 8) {
            return 8;
        } else if(fIEVersion == 9) {
            return 9;
        } else if(fIEVersion == 10) {
            return 10;
        } else {
            return 6;//IE版本<=7
        }
    } else if(isEdge) {
        return 'edge';//edge
    } else if(isIE11) {
        return 11; //IE11
    }else{
        return -1;//不是ie浏览器
    }
}
/**
 * 跳转到IE专属页面
 * url 需要跳转的页面url地址
 */
function goIEPage(ieNumber,url){
    if (ieNumber>8 && ieNumber <= 11 ){
        $(".main-right").empty();
        $(".main-right").load(url);
    }else{

    }
}


/**
 * ie版本图片上传函数
 * @param file   文件input  的ID
 * @param divDom  显示图片盒子的ID
 * @param imgDom  图片img标签ID
 */
function previewImage(file,divDom,imgDom)
{
    var nameFlis = $(file).val();
    var fileName123 = nameFlis.split("\\");
    var fileNameModel = fileName123[fileName123.length-1];
    var endName = fileNameModel.split(".")[1];
    if(endName == 'png' || endName == 'jpg' || endName == 'jpeg' ){


        var MAXWIDTH  = 146;
        var MAXHEIGHT = 146;
        var div = document.getElementById(divDom);
        var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
        file.select();
        file.blur();
        var src = document.selection.createRange().text;
        div.innerHTML = '<img id='+imgDom+'>';
        var img = document.getElementById(imgDom);
        img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
        var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
        status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
        div.innerHTML = "<div id="+divDom+" style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;"+sFilter+src+"\"'></div>";

    }else {
        layer.msg('请选择png、jpg格式文件上传', {icon: 5});
        return

        }
    }
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
    var param = {top:0, left:0, width:width, height:height};
    if( width>maxWidth || height>maxHeight ){
        rateWidth = width / maxWidth;
        rateHeight = height / maxHeight;

        if( rateWidth > rateHeight ){
            param.width =  maxWidth;
            param.height = Math.round(height / rateWidth);
        }else {
            param.width = Math.round(width / rateHeight);
            param.height = maxHeight;
        }
    }
    param.left = Math.round((maxWidth - param.width) / 2);
    param.top = Math.round((maxHeight - param.height) / 2);
    return param;
}


/**
 * 处理分页样式问题
 */
function fenYeProblem(total) {
    if(total>8){
        $("#fenyeBox ul").css({'width':(9 - 1)*40+'px'});
    }else {
        $("#fenyeBox ul").css({'width':total*40+'px'});
    }

}